#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File ：ProductParser.py
@Author ：zqy
@Email : zqingy@work@163.com 
@note: 
"""
from application.Parser import BaseValidator, GETRequestParser, JSONRequestParser


class ProductValidator(BaseValidator):

    @classmethod
    def get(cls) -> GETRequestParser:
        p = GETRequestParser(trim=True)
        p.init_page()
        p.add_argument("category_id", type=int, help="分类ID")
        p.add_argument("search_keyword", type=str, help="搜索关键字")
        p.add_argument("is_hot", type=cls.boolean_by_args, help="热卖")
        p.add_argument("is_new", type=cls.boolean_by_args, help="新品")
        p.add_argument("show_all", type=cls.boolean_by_args, help="展示所有")
        return p

    @classmethod
    def post(cls) -> JSONRequestParser:
        p = JSONRequestParser(trim=True)
        p.add_argument_non_null("name", type=str, help="商品名称")
        p.add_argument_non_null("price", type=float, help="单价")
        p.add_argument_non_null("image_url", type=str, help="商品图片")
        p.add_argument_non_null("unit", type=str, help="单位")
        p.add_argument_non_null("stock", type=int, help="库存")
        p.add_argument_non_null("category_id", type=int, help="分类ID")
        p.add_argument_non_null("is_hot", type=bool, help="是否热销")
        p.add_argument_non_null("is_promo", type=bool, help="是否促销")
        p.add_argument_non_null("is_new", type=bool, help="是否新品")
        p.add_argument_non_null("sort", type=int, help="排序值")
        p.add_argument_non_null("detail", type=str, help="商品详情")
        p.add_argument_non_null("parameter", type=str, help="商品参数")
        p.add_argument_non_null("service", type=str, help="售后保障")
        return p

    @classmethod
    def shelf(cls) -> JSONRequestParser:
        p = JSONRequestParser(trim=True)
        p.add_argument_non_null("usable", type=bool, help="是否上架")
        return p
